import { ConfigBase } from "./configBase/ConfigBase";
import { Cache } from "../cache/Cache";
import { TCrossDefenseUpgrade } from "../../../Message/Db/Tables/TCrossDefenseUpgrade";
import { TDefenseBressUpgrade } from "../../../Message/Db/Tables/TDefenseBressUpgrade";
import { MonsterPlayer } from "../scene/player/entity/MonsterPlayer";
import { CrossDefenceTowerInfo } from "../view/copy/crossDefenceCopy/data/CrossDefenceTowerInfo";
import { BossConfig } from "./BossConfig";
import { Language } from "../../../extend/language/Language";
import { GameConst } from "../../component/gconst/GameConst";
import { SEntityId } from "../../../Message/Public/SEntityId";
import { EntityUtil } from "../scene/layer/utils/EntityUtil";
import { TCrossDefense } from "../../../Message/Db/Tables/TCrossDefense";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { ClassTypesUtil } from "../view/common/ClassTypesUtil";
type int = number;
//class CrossDefenceCopyConfig
    
    export  class CrossDefenceCopyConfig extends ConfigBase
    {
       

        public getInitBuildMenuConfig(): Array<any>
        {
            var loc1=getConfigByKeys(["level", "difficulty"], [1, Cache.instance.crossDefenceCopy.difficulty]);
            loc1.sort(this.sortMenu);
            return loc1;
        }

        /* internal  */sortMenu(arg1: TCrossDefenseUpgrade, arg2: TCrossDefenseUpgrade): int
        {
            if (arg1.type < arg2.type) 
            {
                return -1;
            }
            if (arg1.type > arg2.type) 
            {
                return 1;
            }
            return 0;
        }

        public getInitBlessConfig(): Array<any>
        {
            var loc1=getConfigByKeys(["level"], [1], this._blessUpgrade);
            loc1.sort(this.sortBless);
            return loc1;
        }

        /* internal  */sortBless(arg1: TDefenseBressUpgrade, arg2: TDefenseBressUpgrade): int
        {
            if (arg1.towerType < arg2.towerType) 
            {
                return -1;
            }
            if (arg1.towerType > arg2.towerType) 
            {
                return 1;
            }
            return 0;
        }

        public isCrossCopyTowerBoss(arg1: int): Boolean
        {
            var loc1=null;
            var loc2=0;
            var loc3=_data;
            for(loc1 of loc3) 
            {
                if (loc1.preBoss != arg1) 
                {
                    continue;
                }
                return true;
            }
            return false;
        }

        public getTowerInfoByCode(arg1: int, arg2: MonsterPlayer, arg3: string="x~@#ownerName~@#"): CrossDefenceTowerInfo
        {
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc1;
            if ((loc1 = getConfigByKeys(["preBoss"], [arg1])) == null || loc1.length == 0) 
            {
                return null;
            }
            var loc2=loc1[0] as TCrossDefenseUpgrade;
            var loc3=getConfigByKeys(["type", "level"], [loc2.type, loc2.level + 1]);
            var loc4;
            (loc4 = new CrossDefenceTowerInfo()).config = loc2;
            var loc5;
            if ((loc5 = BossConfig.instance.getInfoByName(arg1)) != null) 
            {
                loc4.name = loc5.name;
            }
            if (loc3 == null || loc3.length == 0) 
            {
                loc4.nextEffectDesc = Language.getString(80297);
                loc4.levelUpNeed = 0;
            }
            else 
            {
                loc4.nextEffectDesc = TCrossDefenseUpgrade(loc3[0]).desc;
                loc4.levelUpNeed = TCrossDefenseUpgrade(loc3[0]).material;
            }
            loc4.recycleBack = this.getUpgrateToMeNeedMaterials(loc2) * GameConst.CrossDefenceRecycleBackRate / 100;
            if (!(arg3 == "x~@#ownerName~@#") && !(arg3 == null)) 
            {
                loc4.owner = arg3;
            }
            else if (!(arg2.entityInfo == null) && !(arg2.entityInfo.entityInfo == null) && !(arg2.entityInfo.entityInfo.toEntitys == null) && arg2.entityInfo.entityInfo.toEntitys.length > 0) 
            {
                loc6 = arg2.entityInfo.entityInfo.guildName;
                loc7 = arg2.entityInfo.entityInfo.toEntitys[0] as SEntityId;
                loc8 = EntityUtil.getProxyName(loc7);
                if (loc7.typeEx == Cache.instance.role.entityInfo.entityId.typeEx && loc6 == Cache.instance.role.entityInfo.name) 
                {
                    loc4.owner = loc6;
                }
                else 
                {
                    loc4.owner = loc8 + "_" + loc6;
                }
            }
            else 
            {
                loc4.owner = "";
            }
            return loc4;
        }

        public getUpgrateToMeNeedMaterials(arg1: TCrossDefenseUpgrade): int
        {
            var loc3=null;
            var loc1=0;
            var loc2=1;
            while (loc2 <= arg1.level) 
            {
                if (!((loc3 = getConfigByKeys(["type", "level"], [arg1.type, loc2])) == null) && loc3.length > 0) 
                {
                    loc1 = loc1 + TCrossDefenseUpgrade(loc3[0]).material;
                }
                ++loc2;
            }
            return loc1;
        }

        public getCopyInfoByDifficulty(arg1: int): TCrossDefense
        {
            return this._copyInfo[arg1.toString()] as TCrossDefense;
        }

        protected /* override */ initConfig(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            _data = new Map<any, any> /* flash.utils.Dictionary */();
            this._copyInfo = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=ConfigManager.instance.getJSONByFileName("t_cross_defense_upgrade.json");
            var loc6=0;
            var loc7=loc1;
            for(loc2 of loc7) 
            {
                loc3 = new TCrossDefenseUpgrade();
                ClassTypesUtil.copyValue(loc3, loc2);
                _data[this.getKey(loc3)] = loc3;
            }
            loc1 = ConfigManager.instance.getJSONByFileName("t_cross_defense.json");
            loc6 = 0;
            loc7 = loc1;
            for(loc2 of loc7) 
            {
                loc4 = new TCrossDefense();
                ClassTypesUtil.copyValue(loc4, loc2);
                this._copyInfo[this.getInfoKIey(loc4)] = loc4;
            }
            this._blessUpgrade = new Map<any, any> /* flash.utils.Dictionary */();
            loc1 = ConfigManager.instance.getJSONByFileName("t_defense_bress_upgrade.json");
            loc6 = 0;
            loc7 = loc1;
            for(loc2 of loc7) 
            {
                loc5 = new TDefenseBressUpgrade();
                ClassTypesUtil.copyValue(loc5, loc2);
                this._blessUpgrade[loc5.curId] = loc5;
            }
            return;
        }

        public getBlessData(arg1: int): TDefenseBressUpgrade
        {
            return this._blessUpgrade[arg1] as TDefenseBressUpgrade;
        }

        public CrossDefenceCopyConfig.get blessUpgrade(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._blessUpgrade;
        }

        public getInfoKIey(arg1: TCrossDefense): string
        {
            return arg1.difficulty.toString();
        }

        public /* override */ getKey(arg1: Object): Object
        {
            return String(arg1["type"]) + "_" + String(arg1["level"]);
        }

        public static get instance(): CrossDefenceCopyConfig
        {
            if (CrossDefenceCopyConfig._instance == null) 
            {
                CrossDefenceCopyConfig._instance = new CrossDefenceCopyConfig();
            }
            return CrossDefenceCopyConfig._instance;
        }

        /* internal */ /* const */TypeNames: Array<any>=["", Language.getString(80292), Language.getString(80293), Language.getString(80294), Language.getString(80295), Language.getString(80296)];

        public /* const */GuideBookURLS: Array<any>=["crossDefenceGuideBookPage1.swf", "crossDefenceGuideBookPage2.swf", "crossDefenceGuideBookPage3.swf", "crossDefenceGuideBookPage4.swf"];

        /* internal */ /* var */_copyInfo: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_blessUpgrade: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: CrossDefenceCopyConfig;
    }
